
auto.waitFor()
launchApp("微信")
//threads.start(xinxiaoxi());

sleep(3000)
toast("开始脚本")
function xinxiaoxi()
{
  while(true)
{
  sleep(3000)
  
var xiaoxi = className("android.widget.TextView").depth(5).drawingOrder("1").packageName("com.tencent.mm").find()
toastLog("消息个数：" + xiaoxi.length)
for (i = 0; i < xiaoxi.length; i++) {
  log("第 " + i + "个id：" + xiaoxi[i].text())
  if (xiaoxi[i].text() == "1") {
    toast("发现一个新消息")

    jinruxiaoxi(xiaoxi[i])
    sleep(500)
    clikbytext("转账给你")
    toast("点击转账给你")
    sleep(500)
    clikbytext("确认收款")
    toast("点击确认收款")
    sleep(1000)
    while(!desc("返回").exists())
    desc("返回").findOne().click()
    toast("点击返回")
    sleep(1000)
    while(desc("返回").exists())
    { back()
    sleep(1000)}
  
    toast("再次返回")
    //back()
sleep(500)
  }
}
}
}

function clikbytext(c_text)
{
    while(!text(c_text).exists())
    {sleep(1000)}
    sleep(1000)
if (text(c_text).exists())
{
 var zuobiao =   text(c_text).findOne(2000).bounds()
 click(zuobiao.centerX(),zuobiao.centerY())
}}
function jinruxiaoxi(kj_xiaoxi) {
  click(kj_xiaoxi.bounds().centerX(), kj_xiaoxi.bounds().centerY())

}